import axios from 'axios'
import qs from 'qs'

// 设置基准路径
// axios.defaults.baseURL = 'http://www.it.com:80/api'
axios.defaults.baseURL = '/api'

// 设置axios可以传递cookie
// axios.defaults.withCredentials = true
axios.defaults.withCredentials = true

// 设置拦截器，当请求的是post，就把数据转换为json格式字符串
axios.interceptors.request.use(function (config) {
  if (config.method === 'post') {
    config.data = qs.stringify(config.data)
    // console.log(config)
  }
  return config
})

// 用户登录
export const userLogin = ({ username, password }) => axios.post('/login/index.php', { username, password })
// export const userLogin = ({ username, password }) => axios.get('/login/index.php', { params: { username, password } })

// 验证用户登录
export const checkLogin = () => axios.get('/login/checkLogin.php')

// 用户退出系统
export const logout = () => axios.get('/login/logout.php')

// 所有资产列表数据查询
export const getHardwareData = (obj) => axios.get('/assets/hardware.php', { params: obj })

// 修改用户密码
export const changePassword = (obj) => axios.post('/login/resetPass.php', obj)

// 仪表盘四个格子数据
export const getDashboard = () => axios.get('/dashboard/dashboard.php')

// 弹窗显示资产状态
export const getAssetsState = () => axios.get('/assets/assetsState.php')

// 新建资产弹框
export const addAssets = (obj) => axios.get('/assets/createAssets.php', { params: obj })

// 删除资产
export const delAssets = (id) => axios.post('/assets/delAssets.php', { id })

// 修改资产-获取当前资产
export const checkAssets = (obj) => axios.get('/assets/checkAssets.php', { params: obj })

// 硬件页-查询渲染硬件列表数据
export const getComponents = (obj) => axios.get('/components/components.php', { params: obj })
// 硬件页-新建硬件数据
export const addComponents = (obj) => axios.post('/components/components.php', obj)
// 硬件页-删除数据
export const delComponents = (id) => axios.delete('/components/components.php', { params: { id: id }
})
// 硬件页-更新数据
export const checkComponents = (obj) => axios.put('/components/components.php', obj)

// 外设页
// 查询渲染外设
export const getPeripheral = (obj) => axios.get('/peripheral/peripheral.php', { params: obj })
// 新建外设
export const createPeripheral = (obj) => axios.post('/peripheral/peripheral.php', obj)
// 删除外设
export const delPeripheral = (id) => axios.delete('/peripheral/peripheral.php', { params: { id: id } })
// 更新数据
export const checkPeripheral = (obj) => axios.put('/peripheral/peripheral.php', obj)

// 耗材页
// 查询渲染耗材
export const getConsumables = (obj) => axios.get('/consumables/consumables.php', { params: obj })
// 新建耗材
export const createConsumables = (obj) => axios.post('/consumables/consumables.php', obj)
// 删除耗材
export const delConsumables = (id) => axios.delete('/consumables/consumables.php', { params: { id: id } })
// 更新数据
export const checkConsumables = (obj) => axios.put('/consumables/consumables.php', obj)

// 许可证
// 渲染许可证列表数据
export const getLicense = (obj) => axios.get('/license/license.php', { params: obj })
// 新建许可证
export const createLicense = (obj) => axios.post('/license/license.php', obj)
// 删除许可证
export const delLicense = (id) => axios.delete('/license/license.php', { params: { id: id } })
// 更新数据
export const checkLicense = (obj) => axios.put('/license/license.php', obj)

// 用户列表
// 查询渲染用户列表
export const getUserlist = (obj) => axios.get('/users/users.php', { params: obj })
export const getUser = () => axios.get('/users/users.php')
// 切换用户状态
export const userStatus = (obj) => axios.put('/users/users.php', obj)
// 新建用户
export const addUser = (obj) => axios.post('/users/users.php', obj)
// 删除用户
export const delUser = (id) => axios.delete('/users/users.php', { params: { id: id } })
// 修改用户
export const checkUser = (obj) => axios.put('/users/users.php', obj)

// 制造商
// 查询渲染制造商
export const getManufacturers = (obj) => axios.get('/setup/manufacturers.php', { params: obj })
export const getManufacturersName = () => axios.get('/setup/manufacturers.php')
// 新建制造商
export const addManufacturers = (obj) => axios.post('/setup/manufacturers.php', obj)
// 删除制造商
export const delManufacturers = (id) => axios.delete('/setup/manufacturers.php', { params: { id: id } })
// 修改制造商
export const checkManufacturers = (obj) => axios.put('/setup/manufacturers.php', obj)

// 资产类型
// 查询渲染资产类型
export const getCategories = (obj) => axios.get('/setup/categories.php', { params: obj })
export const getCategoriesName = () => axios.get('/setup/categories.php')
// 查询显示资产状态类型
export const getCategoriesStatus = () => axios.get('/setup/categories_status.php')
// 删除资产类型
export const delCategories = (id) => axios.delete('/setup/categories.php', { params: { id: id } })
// 新建资产类型
export const addCategories = (obj) => axios.post('/setup/categories.php', obj)
// 修改资产类型
export const checkCategories = (obj) => axios.put('/setup/categories.php', obj)

// 资产型号
// 查询渲染资产型号
export const getModels = (obj) => axios.get('/setup/models.php', { params: obj })
export const getModelsName = () => axios.get('/setup/models.php')
// 新建资产型号
export const addModels = (obj) => axios.post('/setup/models.php', obj)
// 删除资产型号
export const delModels = (id) => axios.delete('/setup/models.php', { params: { id: id } })
// 修改资产型号
export const checkModels = (obj) => axios.put('/setup/models.php', obj)

// 供应商
// 查询渲染供应商
export const getSuppliers = () => axios.get('/setup/suppliers.php')
// 新建供应商
export const addSuppliers = (obj) => axios.post('/setup/suppliers.php', obj)
// 删除供应商
export const delSuppliers = (id) => axios.delete('/setup/suppliers.php', { params: { id: id } })
// 修改资产型号
export const checkSuppliers = (obj) => axios.put('/setup/suppliers.php', obj)

// 公司
// 查询渲染公司
export const getCompanies = () => axios.get('/setup/companies.php')
export const getCompaniesName = () => axios.get('/setup/companies.php')
// 新建公司
export const addCompanies = (obj) => axios.post('/setup/companies.php', obj)
// 删除公司
export const delCompanies = (id) => axios.delete('/setup/companies.php', { params: { id: id } })
// 修改公司
export const checkCompanies = (obj) => axios.put('/setup/companies.php', obj)

// 部门
// 查询渲染部门
export const getDepartment = () => axios.get('/setup/departments.php')
// 新建部门
export const addDepartment = (obj) => axios.post('/setup/departments.php', obj)
// 删除部门
export const delDepartment = (id) => axios.delete('/setup/departments.php', { params: { id: id } })
// 修改部门
export const checkDepartment = (obj) => axios.put('/setup/departments.php', obj)

// 折旧
// 查询渲染折旧
export const getDepreciation = () => axios.get('/setup/depreciations.php')
// 新建折旧
export const addDepreciation = (obj) => axios.post('/setup/depreciations.php', obj)
// 删除折旧
export const delDepreciation = (id) => axios.delete('/setup/depreciations.php', { params: { id: id } })
// 修改折旧
export const checkDepreciation = (obj) => axios.put('/setup/depreciations.php', obj)
